var question_data   = new Array();
var question_author = new Array();
var question_code   = new Array();
var quiz_url = "";
var page  = 0;
var total = 0;
var questionString = "";
function checkquiz(){
    var d = new Date();
    var year = d.getFullYear();
    var month = d.getMonth() + 1;
    var day = d.getDate();

	var xmlUrl = 'http://example/quiz2u/api/list?after='+ year + '-' + month + '-' +day;

	var title = 'Quiz2Uリスト';
	var update = false;
	var ver = 0;
	var updateLink = '';
    question_data   = new Array();
    question_author = new Array();
    question_code   = new Array();
	request = new XMLHttpRequest();
	request.open('GET', xmlUrl, true);
	request.send();
	request.onreadystatechange = function(){
		if(this.readyState==4 && this.status==200){
			var data;
			if(this.responseText){
				data = eval('(' + this.responseText + ')');;
			}
            for (var i = 0; i < data.quizzes.length; i++ ){
                question_data.push(Latin1toUtf8(data.quizzes[i].question));
                question_author.push(Latin1toUtf8(data.quizzes[i].author));
                question_code.push(data.quizzes[i].code);
            }
            total = data.quizzes.length;
            next();
            updateQuiz.ticking = true;
		}
	};
}

function next(){
            if( total == 0 ){
                updateQuiz.ticking = false;
                return;
            }
            question.data   =  "";
            question.hOffset = 10;
            question.vOffset = 40;
            question.data = question_data[page];
            quiz_url = 'http://example.internal/answer/' + question_code[page];
            page++;
            if( page >= total ){
                page = 0;                
            }
}

function openQuestionPage(){
    openURL(quiz_url);
}

Latin1_ary = [8364,0,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,0,381,0,0,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,0,382,376]
latin1=String.fromCharCode.apply(String,Latin1_ary);
Latin1_reg = [];for(var i=0;i<Latin1_ary.length; i++){ if(Latin1_ary[i]!=0) Latin1_reg.push(Latin1_ary[i]) };Latin1_reg = new RegExp( "["+String.fromCharCode.apply(String,Latin1_reg)+"]", "g" );
    function unLatin1(str){
      return str.replace( Latin1_reg,function(m){
        var i=latin1.indexOf(m[0]);
        if(i!=-1)c=i+128;
        return String.fromCharCode(c);
      } );
    }
Utf8_reg = /[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf3][\x80-\xbf][\x80-\xbf][\x80-\xbf]|\xf4[\x80-\x8f][\x80-\xbf][\x80-\xbf]/g
function Utf8ToString(str){
      return str.replace( Utf8_reg, function(s){
        var c = s.charCodeAt(0);
        if((c > 191) && (c < 224)) {
          return String.fromCharCode(((c & 31) << 6) | (s.charCodeAt(1) & 63));
        } else {
          return String.fromCharCode(((c & 15) << 12) | ((s.charCodeAt(1) & 63) << 6) | (s.charCodeAt(2) & 63));
        }
      });
}
function Latin1toUtf8(str){ return Utf8ToString(unLatin1(str))}

